import {getCustomNav} from '@/util/util.js'
import {uploadFile} from '@/api/file.js'
import config from'@/config.js';
export default{
	methods:{
		navigate(url){
			if(url)uni.navigateTo({url});
		},
		back(){
			uni.navigateBack({
				fail(){
					uni.switchTab({
						url:'/pages/index/index'
					})
				}
			})
		},
		chooseImage(type,max){
			uni.chooseMedia({
				count:max-this.form[type].length,
				sizeType:['compressed'],
				mediaType:['image'],
				success:async (res)=>{
					for (let item of res.tempFiles) {
						if(this.form[type].length>=max){
							break;
						}
						let url=await uploadFile(item.tempFilePath)
						this.form[type].push(url)
					}
				}
			})
		},
		deleteImage(type,index){
			uni.showModal({
				title:'提示',
				content:'确定删除吗',
				success: (e) => {
					if(e.confirm){
						this.form[type].splice(index,1);
					}
				}
			})
		},
		viewImage(type,url){
			uni.previewImage({
				current:url,
				urls:this.form[type]
			})
		},
		call(phone){
			uni.makePhoneCall({
				phoneNumber:phone
			})
		},
		openMap(latitude,longitude,name){
			uni.openLocation({
				latitude:latitude*1,
				longitude:longitude*1,
				name
			})
		}
	},
	computed:{
		mt(){
			let custom=getCustomNav();
			return custom.statusBar+custom.nvaMartom+custom.navHeight+40+'rpx';
		}
	},
	data(){
		return{
			cloudStorage:config.cloudStorage,
		}
	},
	onPageScroll(e) {
		this.topBgColor=e.scrollTop >= 1?'#64b548':'rgba(0,0,0,0)'
		this.titleColor=e.scrollTop >= 1?'#fff':'#000'
	}
}
